package cn.edu.ujn.exam.controller;

import java.util.List;

import org.apache.tomcat.jni.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.edu.ujn.exam.dao.UserInfo;
import cn.edu.ujn.exam.service.IUserService;

public class UserController {
	@Autowired
	private IUserService userService;
	@RequestMapping("/findById")
	public String findCustomerById(int id,Model model) {
		
		User findUserById = userService.findUserById(id);
		model.addAttribute("user", findUserById);
		return "user";
	}
	@RequestMapping(value="/addUser",method=RequestMethod.GET)
	public String toAdd() {
		return "addUser";
	}
	
	@RequestMapping(value="/addCustomer",method=RequestMethod.POST)
	public String addCustomer(UserInfo c) {
		int insert = userService.insert(c);
		return "addUser";
	}
	@RequestMapping("/selectAll")
	public String selectAll(Model model) {
		List<User> selectAll = userService.selectAll();
		model.addAttribute("list",selectAll);
		return "listCustomer";
	}
	@RequestMapping(value="/updateCustomer")
	public String updateCustomer(UserInfo c) {
		int update = userService.update(c);
		return "updateCustomer";
	}
	@RequestMapping(value="/deleteCustomer")
	public String deleteCustomer(UserInfo c) {
		int delete = userService.delete(c);
		return "deleteCustomer";
	}

}
